//
//  BoxCostHeadView.m
//  XLDoctor
//
//  Created by longma on 2018/10/8.
//  Copyright © 2018年 XLH. All rights reserved.
//

#import "MJUICellImageBTextView.h"

@implementation MJUICellImageBTextView


- (void)awakeFromNib{
    [super  awakeFromNib];
    
    self.leftImageView.hidden = true;
    if(self.iconName){
        self.leftImageView.image = MJUIImageMake(self.iconName);
        self.leftImageView.hidden = false;
    }
    if(self.title){
        self.titleLabel.mj_localizable = self.title;
    }
    if(self.subTitle){
        self.subTitleTextField.text = self.subTitle;
    }
    if(self.hideLine){
        self.horLine.hidden = self.hideLine;
    }
    if(self.hideRightImageView){
        self.rightImageView.hidden = self.hideRightImageView;
    }
    if(self.subTitleColorName){
        self.subTitleTextField.textColor = [UIColor mj_colorName:self.subTitleColorName];
    }
    
    self.backgroundColor = UIColor.clearColor;
    
    if(self.itemType == 1){
        self.leftImageViewW.constant = 30;
        self.leftImageViewH.constant = 30;
    }
    
    self.subTitleTextField.hidden = true;
    
    self.placeholderLabel.hidden = false;
    self.contentLabel.hidden = true;
    MJWeakSelf
    [[RACSignal merge:@[self.subTitleTextField.rac_textSignal, RACObserve(self.subTitleTextField, text),]] subscribeNext:^(NSString* text){
        if(text.length){
            weakSelf.placeholderLabel.hidden = true;
            weakSelf.contentLabel.hidden = false;
        }else{
            weakSelf.placeholderLabel.hidden = false;
            weakSelf.contentLabel.hidden = true;
        }
        weakSelf.contentLabel.text = text;
        
        if(!weakSelf.subTitlePlaceholder.length){
            weakSelf.placeholderLabel.hidden = true;
        }
    }];
    
    //如果超过3行，缩小字体
    self.titleLabel.adjustsFontSizeToFitWidth = true;
}

- (void)setSubTitle:(NSString *)subTitle {
    self.subTitleTextField.text = subTitle;
}

- (void)setSubTitlePlaceholder:(NSString *)subTitlePlaceholder {
    _subTitlePlaceholder = subTitlePlaceholder;
    
    self.placeholderLabel.mj_localizable = subTitlePlaceholder;
    
    self.placeholderLabel.hidden = false;
    self.contentLabel.hidden = true;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
     
}

@end
